package com.corpgovernment.travelstandard.controller;

import com.corpgovernment.api.travelstandard.bo.TrainTransferStandardDetailRequestBO;
import com.corpgovernment.api.travelstandard.bo.TrainTransferStandardDetailResponseBO;
import com.corpgovernment.api.travelstandard.bo.TrainTransferStandardRequestBO;
import com.corpgovernment.api.travelstandard.bo.TrainTransferStandardResponseBO;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.travelstandard.impl.TrainTransferStandardService;
import com.corpgovernment.travelstandard.vo.*;
import com.corpgovernment.travelstandard.vo.train.*;
import com.ctrip.corp.obt.generic.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 接送机控制器
 */
@Slf4j
@RestController
@RequestMapping("trainTransfer")
public class TrainTransferStandardManageController {

	@Autowired
	private TrainTransferStandardService trainTransferStandardService;

	/**
	 * 获取接送机差标详情
	 */
	@PostMapping("/get")
	public JSONResult<GetTrainTransferStandardResponseVO> getTransferStandard(@RequestBody @Valid GetTrainTransferStandardRequestVO request) {
		return JSONResult.success(trainTransferStandardService.getStandard(request));
	}

	/**
	 * 新增差标获取模版数据
	 */
	@PostMapping("/toAdd")
	public JSONResult<InitStandardResponseVO<TrainTransferControlVO>> toAdd(@RequestBody @Valid InitStandardRequestVO request) {
		return JSONResult.success(trainTransferStandardService.init(request));
	}

	/**
	 * 修改差标名称
	 *
	 * @return
	 */
	@PostMapping("/updateStandardName")
	public JSONResult<UpdateNameResponseVO> updateStandardName(@RequestBody UpdateNameRequestVO request) {
		return JSONResult.success(trainTransferStandardService.updateStandardName(request));
	}

	/**
	 * 新增差标
	 *
	 * @param request
	 * @return
	 */
	@PostMapping("/save")
	public JSONResult<SaveTrainTransferControlResponseVO> save(@RequestBody @Valid SaveTrainTransferControlRequestVO request) {
		return JSONResult.success(trainTransferStandardService.save(request));
	}

	/**
	 * 更新接送机rc信息
	 *
	 * @param request
	 * @return
	 */
	@PostMapping("/updateRc")
	public JSONResult<UpdateReasonCodeResponseVO> updateRc(@RequestBody @Valid UpdateReasonCodeRequestVO request) {
		return JSONResult.success(trainTransferStandardService.updateRc(request));
	}

	/**
	 * 删除差标
	 *
	 * @param request
	 * @return
	 */
	@PostMapping("/delete")
	public JSONResult<DeleteStandardResponseVO> delete(@RequestBody @Valid DeleteStandardRequestVO request) {
		return JSONResult.success(trainTransferStandardService.delete(request));
	}

	/**
	 * 接送站差标描述
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping("getTravelStandard")
	public JSONResult<TrainTransferStandardResponseBO> getTravelStandard(@RequestBody @Valid TrainTransferStandardRequestBO request) {
		log.info("接送站差标描述 getTravelStandard:{}", JsonUtils.toJsonString(request));
		return JSONResult.success(trainTransferStandardService.getTravelStandard(request));
	}

	/**
	 * 接送机差标
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping("getTravelStandardDetail")
	public JSONResult<TrainTransferStandardDetailResponseBO> getTravelStandardDetail(@RequestBody @Valid TrainTransferStandardDetailRequestBO request) {
		return JSONResult.success(trainTransferStandardService.getTravelStandardDetail(request));
	}

}
